import json
from django.http import HttpResponse
from django.shortcuts import render


def start(request):
    return render(request, "main.html")


def showOne(request):
    year = request.GET.get('year')
    print(year)
    date = str(year)

    f = open('templates/common/showIndex.json', 'r', encoding='utf-8')
    bigJson = f.read()
    f.close()
    bigDict = json.loads(bigJson)
    data = bigDict[date]

    person = {"data": data}
    print(person)
    response = HttpResponse(json.dumps(person), content_type='application/json; charset=utf-8')
    return response


def showPredict(request):
    f = open('templates/common/showPredict.json', 'r', encoding='utf-8')
    bigJson = f.read()
    f.close()
    bigDict = json.loads(bigJson)
    data = bigDict["data"]

    person = {"data": data}
    print(person)
    response = HttpResponse(json.dumps(person), content_type='application/json; charset=utf-8')
    return response
